package be.nvlooy.moviereminder.service;

import java.util.GregorianCalendar;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import be.nvlooy.moviereminder.entities.LanguageType;
import be.nvlooy.moviereminder.entities.User;
import be.nvlooy.moviereminder.service.implementations.UserServiceImpl;

public class addTestData {
	
	EntityManagerFactory emf;
	EntityManager em;
	private UserServiceImpl userService;
	
	public static void main(String[] args) throws Exception {
		addTestData test = new addTestData();
		test.init();
		test.addData();
	}
	
	public void init() throws Exception {
		emf = Persistence.createEntityManagerFactory("moviereminderdb");
		em = emf.createEntityManager();
		userService = new UserServiceImpl();
		userService.setEntityManager(em);
	}

	public void addData() {		
		EntityTransaction tx = em.getTransaction();
		tx.begin();
		
		User user = new User();
		user.setUsername("pluto");
		user.setEmail("TEST");
		user.setAndGeneratePassword("test");
	    user.setActive(true);
	    user.setAdmin(true);
	    user.setFirstName("Nik");
	    user.setName("Van Looy");
	    user.setDateCreated(GregorianCalendar.getInstance().getTime());
	    user.setLanguage(LanguageType.EN);
	    userService.addUser(user);
	    
		user = new User();
		user.setUsername("bob");
		user.setEmail("TEST");
		user.setAndGeneratePassword("test");
	    user.setActive(true);
	    user.setAdmin(false);
	    user.setFirstName("Bob");
	    user.setName("Dylan");
	    user.setDateCreated(GregorianCalendar.getInstance().getTime());
	    user.setLanguage(LanguageType.EN);
	    userService.addUser(user);
	    
		user = new User();
		user.setUsername("jimi");
		user.setEmail("TEST");
		user.setAndGeneratePassword("test");
	    user.setActive(true);
	    user.setAdmin(false);
	    user.setFirstName("Jimi");
	    user.setName("Hendrix");
	    user.setDateCreated(GregorianCalendar.getInstance().getTime());
	    user.setLanguage(LanguageType.EN);
	    userService.addUser(user);
	    
		user = new User();
		user.setUsername("lou");
		user.setEmail("TEST");
		user.setAndGeneratePassword("test");
	    user.setActive(true);
	    user.setAdmin(false);
	    user.setFirstName("Lou");
	    user.setName("Reed");
	    user.setDateCreated(GregorianCalendar.getInstance().getTime());
	    user.setLanguage(LanguageType.EN);
	    userService.addUser(user);
	    

	    
	    tx.commit();
	}
	
}
